%script to run PICS PTV analysis

%% 
pnseq='C:\Users\gracec\Documents\PICS DATA\YR140918\Analysis top\Sequences\';  %Path containing the SEQ files
pnout='C:\Users\gracec\Documents\PICS DATA\YR140918\Analysis Top\Analysis PTV bwt pi 20\'; %Path to write resultsif ~exist(pnout,'file')
if ~exist(pnout,'file') %if output directory doesn't exist, create it
    mkdir(pnout);
end

files=dir(fullfile(pnseq,'*.seq'));  %List of sequence files
nf=length(files); %number of files
%nf=3;  %file to stop (good for initial testing)
nstart=1; %starting index for list of files%
%nf=20;
%Loop for processing files
for k=nstart:nf
    fnseq=fullfile(pnseq,files(k).name); %construct the full path to the SEQ file
   fnout=fullfile(pnout,['ptv_',strrep(files(k).name,'.seq','.mat')]); %same for output file
   hdr=load_SEQ(fnseq); %get HDR information from SEQ file
   fps=hdr.FrameRate; %the framerate
   %ptv=im_ptv(fnseq,fps); %PTV contains the output struct for PTV analysis
   %ptv=im_ptv_kaf(fnseq,fps); %PTV contains the output struct for PTV analysis
   %ptv=im_ptv_bwt15(fnseq,fps); %PTV contains the output struct for PTV analysis-Save "R"
    ptv=im_ptv_v3(fnseq,fps,20);  %Last input is user defined bwt threshold
   save(fnout,'ptv','-v7') %save to file
end
